﻿using Autofac;
using DTM.Core.Utils;
using DTM.Model;
using DTM.WinApp.Players;
using System;
using System.Windows.Forms;

namespace DTM.WinApp
{
    /// <summary>
    /// Class declare manager of DTM UI.
    /// </summary>
    public class ApplicationManager : IApplicationManager
    {
        #region Fields

        private readonly IComponentContext _container;

        #endregion Fields

        #region Constructors

        public ApplicationManager(IComponentContext container)
        {
            Validate.NotNull<ArgumentNullException>(container, "container");
            _container = container;
        }

        #endregion Constructors

        #region Methods

        /// <summary>
        /// Shows generic error message window;
        /// </summary>
        /// <param name="message">Message to display.</param>
        public void ShowErrorMessage(string message)
        {
            string caption = "Error";
            MessageBoxButtons buttons = MessageBoxButtons.OK;
            MessageBox.Show(message, caption, buttons);
        }

        public void ShowNewTournament()
        {
            throw new NotImplementedException();
            // (new TournamentForm()).Show();
        }

        /// <summary>
        /// Show add player view.
        /// </summary>
        /// <returns></returns>
        public bool ShowPlayerView()
        {
            return ShowPlayerView(null);
        }

        /// <summary>
        /// Show edit player view;
        /// </summary>
        /// <param name="player">Player to edit</param>
        /// <returns></returns>
        public bool ShowPlayerView(IPlayer player)
        {
            var form = _container.Resolve<IPlayerView>();
            form.Initialize(player);
            var result = form.ShowDialog();
            return result == DialogResult.OK;
        }

        /// <summary>
        /// Show all players view.
        /// </summary>
        public void ShowPlayersView()
        {
            var form = _container.Resolve<IPlayersView>();
            form.ShowDialog();
        }

        #endregion Methods
    }
}